package com.entities;

import java.io.InputStream;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.fetch.JSONParser;

import android.util.SparseArray;

public class Item {
	private int id;
	private String name;
	private static SparseArray<String> spar;
	
	public static final String baseImgUrl = "http://cdn.dota2.com/apps/dota2/images/items/";
	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}
	
	public Item(int id, String name) {
	
		this.id = id;
		this.name = name;
	}
	
	public SparseArray<String> getItemAsSparseArray(){
		SparseArray<String> sa = new SparseArray<String>();
		sa.put(id, name);
		return sa;
	}

	public static SparseArray<String> getAllItemsAsSparseArray(InputStream in){
		if(spar==null){ 
		spar = new SparseArray<String>();
		try {
			JSONArray json = JSONParser.getJsonObjFromInputStream(in).getJSONArray("items");
		for(int cont =0; cont < json.length(); cont++){
			JSONObject jo = json.getJSONObject(cont);
	
			spar.put(jo.getInt("id"), jo.getString("name"));
		}
		
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		}
		return spar;
		
	}


}
